

*********************************************
*
* Figure 1. Percentage of New Mortgage Offers Fully Amortizing
*
* 
*********************************************
use "H:\InkomenBestedingen\Data\AB\sample_HDN.dta", clear
	
		gen mtg_bal_full_amort_tmp = full_amort*total_loan_amt if include_hdn==1
		gen mtg_bal_tmp = total_loan_amt if include_hdn==1
		
		bys date_ym: egen mtg_bal_full_amort = mean(mtg_bal_full_amort_tmp)
		bys date_ym: egen mtg_bal = mean(mtg_bal_tmp)
		
		gen perc_mtg_bal_full_amort = 100* mtg_bal_full_amort/mtg_bal
		
		duplicates drop date_ym, force
		graph twoway (connected perc_mtg_bal_full_amort date_ym, msize(tiny) color(black))  , ///
			ysc(r(0(0.1)1)) legend(size(small) ) ylabel(0 20 40 60 80 100) tline(2012m12, lpattern(dash) lcolor(black)) /// 
			xlabel(,labsize(small)) ///
				tlabel(2011m1(6)2014m8, format(%tmMon_CCYY)) graphregion(color(white)) xtitle("Mortgage Offer Date") ytitle("%") title("")


*********************************************
*
* Figure 2 - Panel A: Amortization & Wealth Accumulation in 2015 
*
use "H:\InkomenBestedingen\Data\AB\sample_main.dta", clear

* Create dummy variables by month
forval yr = 2012/2013 {
forval month = 1/12 {
	gen datedum_`yr'_`month' = (buy_year==`yr' & buy_month==`month')
}
}

* Label months
forval yr = 2012/2013 {
	forval month = 1/12 {
		if `month'==1 {
			label var datedum_`yr'_`month' `"Jan"'
		}
		if `month'==2 {
			label var datedum_`yr'_`month' `"Feb"'		
		}
		if `month'==3 {
			label var datedum_`yr'_`month' `"Mar"'		
		}
		if `month'==4 {
			label var datedum_`yr'_`month' `"Apr"'		
		}
		if `month'==5 {
			label var datedum_`yr'_`month' `"May"'		
		}
		if `month'==6 {
			label var datedum_`yr'_`month' `"Jun"'		
		}
		if `month'==7 {
			label var datedum_`yr'_`month' `"Jul"'		
		}
		if `month'==8 {
			label var datedum_`yr'_`month' `"Aug"'		
		}
		if `month'==9 {
			label var datedum_`yr'_`month' `"Sep"'		
		}
		if `month'==10 {
			label var datedum_`yr'_`month' `"Oct"'		
		}
		if `month'==11 {
			label var datedum_`yr'_`month' `"Nov"'		
		}
		if `month'==12 {
			label var datedum_`yr'_`month' `"Dec"'		
		}			
		
		if `yr'==2012 & `month'==8 {
			label var datedum_`yr'_`month' `""Aug" "2012""'		
		}
		if `yr'==2013 & `month'==8 {
			label var datedum_`yr'_`month' `""Aug" "2013""'		
		}		
	}
}			

drop datedum_2013_2
	
areg wealth_15_14 datedum_* , absorb(dummy) cluster(household_id)
	estimates store wealth_15_14
areg mtg_bal_repay_15_14 datedum_* , absorb(dummy) cluster(household_id)
	estimates store mtg_bal_repay_15_14	
areg net_liquid_savingsplus_15_14 datedum_* , absorb(dummy) cluster(household_id)
	estimates store net_liq_savspl_15_14
	
* Note: transform(*=min(max(@,-2400),2400)) designed to prevent irrelevant high parts of CIs from shrinking observable portion
* of coefficients (which are unaffected by this as can be seen in the figure).
coefplot ///
	(wealth_15_14, transform(*=min(max(@,-2400),2400)) lcolor(gray) ciopts(color(gray)) mcolor(gray) lpattern(dash))    ///
	(mtg_bal_repay_15_14, transform(*=min(max(@,-2400),2400)) lcolor(black) mcolor(black) ciopts(color(black)) )  ///
	(net_liq_savspl_15_14, transform(*=min(max(@,-2400),2400)) lcolor(dkorange) mcolor(dkorange) ciopts(color(dkorange)) lpattern(shortdash)    ) ///
	, nooffsets vertical keep(datedum_*) recast(connected) xlabel(,labsize(small) )  /// 
	title("") graphregion(color(white)) msize(tiny)   ysc(r(-2400 2400) axis(1)) ///
	ytitle("Jan-Dec 2015", size(small) axis(1)) ///
	ylabel(-2000 "-{&Euro}2,000" -1000 "-{&Euro}1,000" 0 "{&Euro}0" 1000 "{&Euro}1,000" 2000 "{&Euro}2,000",  labsize(small) )  ///
	legend( order(4 "{&Euro}MTG Amortization '15" 2 "{&Euro}{&Delta}Wealth '2015"6 "{&Euro}{&Delta}Net-liquid Savings{superscript:+} '15") size(vsmall) cols(1) ring(0) position(8)) ///
	ylabel(,nogrid) addplot(pci -2400 10 2400 10, lcolor(red) || pci 0 0 0 20, lcolor(gs3) lwidth(thin) )	///
	text(-2750 -0.75 "{bf:Cohort}" , size(small)) ///
	text(-2950 -0.25 "(home purchase date)", size(vsmall)) ///
	title("")
	
*********************************************
*
* Figure 2 - Panel B. Timing of home closings, April 2012 - December 2013 
*
* 
	
bys ym_trans: egen num_obs = count(mtg_bal_repay_15_14) if mtg_bal_repay_15_14!=.	
areg num_obs datedum_* , absorb(dummy) cluster(household_id)
estimates store num_obs

* Note: transform(*=@+4335) shifts all coefficients up to account for the baseline average so this shows
* transactions per month using the same coefplot formatting above but shows levels not just deviations from
* the omitted group.
coefplot (num_obs, label("") transform(*=@+4335) lcolor(sienna) ciopts(color(%0)) mcolor(sienna)   ) ///
	, nooffsets vertical keep(datedum_*) recast(connected) xlabel(,labsize(small) )  /// 
	title("") graphregion(color(white)) msize(tiny)   ///
	ytitle("# Home Purchases", size(small) ) ///
	ysc(r(0 10000) ) ///
	ylabel(0 "0" 5000 "5,000" 10000 "10,000", labsize(small) )  ///		
	ylabel(,nogrid) addplot(pci 0 10 10000 10, lcolor(red)  )	///
	text(-700 -0.4 "{bf:Cohort}" , size(small)) ///
	text(-1150 0.1 "(home purchase date)", size(vsmall)) 	
	
*********************************************
*
* Figure 3. Amortization and Wealth Accumulation: Cohort Estimates (Life-events)
*
* 
preserve

use "H:\InkomenBestedingen\Data\AB\sample_life_event_mover.dta", clear

cap drop q_datedum_*
forval yr = 2012/2013 {
	forval quarter = 1/4 {
		gen q_datedum_`yr'_`quarter' = (year_life_event==`yr' & year_quarter_life_event==`quarter')
		label var q_datedum_`yr'_`quarter' `yr'Q`quarter'
	}
}			
			
forval yr = 2012/2013 {
forval quarter = 1/4 {
	if `quarter'==1 {
		label var q_datedum_`yr'_`quarter' "Q1"
	}
	if `quarter'==2 {
		label var q_datedum_`yr'_`quarter' "Q2"		
	}
	if `quarter'==3 {
		label var q_datedum_`yr'_`quarter' "Q3"
	}
	if `quarter'==4 {
		label var q_datedum_`yr'_`quarter' "Q4"
	}

	if `yr'==2012 & `quarter'==3 {
		label var q_datedum_`yr'_`quarter' `""Q3" "2012""'		
	}
	if `yr'==2013 & `quarter'==3 {
		label var q_datedum_`yr'_`quarter' `""Q3" "2013""'		
	}		
}
}				

drop q_datedum_2012_4
drop q_datedum_2013_1
	
areg mtg_bal_repay_15_14 q_datedum_* if life_event_sample==1, absorb(dummy) cluster(household_id)
	estimates store mtg_bal_repay_15_14	
areg wealth_15_14 q_datedum_* if life_event_sample==1 , absorb(dummy) cluster(household_id)
	estimates store wealth_15_14

* Note: transform(*=min(max(@,-1500),1500)) designed to prevent irrelevant high parts of CIs from shrinking observable portion
* of coefficients (which are unaffected by this as can be seen in the figure).
coefplot ///
	(wealth_15_14, transform(*=min(max(@,-1500),1500)) axis(1) lcolor(black) mcolor(black) ciopts(color(black)) lpattern(dash) offset(0.1) ) /// 
	(mtg_bal_repay_15_14, transform(*=min(max(@,-1500),1500)) axis(1) lcolor(gray) ciopts(color(gray)) mcolor(gray) offset(-0.1)  ) ///
	, vertical keep(q_datedum_*) xlabel(,labsize(small) )  /// 
	title("") graphregion(color(white)) msize(tiny)   ysc(r(-1500 1500) axis(1)) ///
	ytitle("Jan-Dec 2015" , size(small) axis(1)) ///
	ylabel(-1000 `"-{&Euro}1,000"' -500 `"-{&Euro}500"' 0 "{&Euro}0" 500 `"{&Euro}500"' 1000 `"{&Euro}1,000"', axis(1) labsize(small) )  ///
	legend( order(1 "{&Euro}{&Delta}Wealth '15" 3 "{&Euro}MTG Amortization '15") size(vsmall) cols(1) ring(0) position(8)) ylabel(,nogrid) ///
	addplot(pci -1500 3.5 1500 3.5, lcolor(red) || pci 0 0 0 7, lcolor(gs3) lwidth(thin) )	///
	text(-1735 0.5 "{bf:Cohort}" , size(small)) ///
	text(-1835 0.5 "({ul:{bf:life-event}} date)", size(vsmall) color(red)) 

restore

*********************************************
*
* Figure 4. Amortization and Wealth Accumulation: Diff-in-Diff Estimates
*
* 

preserve

use "H:\InkomenBestedingen\Data\AB\sample_event_study.dta", clear

areg net_worth treated_did_main_2007 treated_did_main_2008 treated_did_main_2009 treated_did_main_2010 treated_did_main_2011 o.treated_did_main_2012 treated_did_main_2013 treated_did_main_2014 treated_did_main_2015 treated_did_main_2016 treated_did_main_2017 treated_did_main if sample_did_main, absorb(year) cluster(household_id)
	estimates store net_worth

areg liquid_savings treated_did_main_2007 treated_did_main_2008 treated_did_main_2009 treated_did_main_2010 treated_did_main_2011 o.treated_did_main_2012 treated_did_main_2013 treated_did_main_2014 treated_did_main_2015 treated_did_main_2016 treated_did_main_2017 treated_did_main if sample_did_main, absorb(year) cluster(household_id)
	estimates store liquid_savings	

areg home_equity treated_did_main_2007 treated_did_main_2008 treated_did_main_2009 treated_did_main_2010 treated_did_main_2011 o.treated_did_main_2012 treated_did_main_2013 treated_did_main_2014 treated_did_main_2015 treated_did_main_2016 treated_did_main_2017 treated_did_main if sample_did_main, absorb(year) cluster(household_id)
	estimates store home_equity	
		
coefplot net_worth liquid_savings home_equity,  xline(6, lcolor(blue) lpattern(dash)) /// 
	nooffsets vertical keep(treated_did_main_*) recast(connected) xlabel(,labsize(small)) xtitle("", size(small)) /// 
	ytitle("") title("") graphregion(color(white)) msize(tiny) omitted legend(order(2 "Total Savings (net-worth)" 6 "Home Equity" 4 "Liquid Savings"))	

restore

*********************************************
*
* Figure 5. Labor Supply by Purchase Cohort Plot - Hours Worked
*
* 		

reghdfe work_hrs_15_12 ///
	datedum_2012_4 datedum_2012_5 datedum_2012_6 datedum_2012_7 datedum_2012_8 datedum_2012_9 datedum_2012_10 datedum_2012_11 o.datedum_2012_12 ////
	o.datedum_2013_1 o.datedum_2013_2 datedum_2013_3 datedum_2013_4 datedum_2013_5 datedum_2013_6 datedum_2013_7 datedum_2013_8 datedum_2013_9 datedum_2013_10 datedum_2013_11 datedum_2013_12 ///
	income_2010 liquid_savings_2010, absorb(i.municipality##i.income_2011_groups) cluster(municipality)
estimates store work_hrs_15_12
		
reghdfe mtg_bal_repay_15_14 ///
	datedum_2012_4 datedum_2012_5 datedum_2012_6 datedum_2012_7 datedum_2012_8 datedum_2012_9 datedum_2012_10 datedum_2012_11 o.datedum_2012_12 ////
	o.datedum_2013_1 o.datedum_2013_2 datedum_2013_3 datedum_2013_4 datedum_2013_5 datedum_2013_6 datedum_2013_7 datedum_2013_8 datedum_2013_9 datedum_2013_10 datedum_2013_11 datedum_2013_12 ///
	income_2010 liquid_savings_2010, absorb(i.municipality##i.income_2011_groups) cluster(municipality)
estimates store mtg_bal_repay_15_14	

* Note: transform(*=min(max(@,-3000),3000)) and transform(*=min(max(@,-250),150)) designed to prevent irrelevant high parts of CIs from shrinking observable portion
* of coefficients (which are unaffected by this as can be seen in the figure).
coefplot ///
	(mtg_bal_repay_15_14, axis(1) transform(*=min(max(@,-3000),3000)) lcolor(black) ciopts(color(black)) mcolor(black)   ) ///
	(work_hrs_15_12, axis(2) label("") transform(*=min(max(@,-250),150)) lcolor(sienna) ciopts(color(sienna)) mcolor(sienna)   ) ///
	, nooffsets vertical keep(datedum_*) recast(connected) xlabel(,labsize(small) )  /// 
	title("") graphregion(color(white)) msize(tiny)   ysc(r(-2600 2600) axis(1)) ///
	ytitle("Jan-Dec 2015", size(small) axis(1)) ///
	ytitle("Change in # of Hours worked 2015 - 2012", size(small) axis(2)) ///
	ysc(r(-250 150) axis(2)) ///
	ylabel(-3000 "-{&Euro}3,000" -2000 "-{&Euro}2,000" -1000 "-{&Euro}1,000" 0 "{&Euro}0" 1000 "{&Euro}1,000" 2000 "{&Euro}2,000" 3000 "{&Euro}3,000",  labsize(small) )  ///
	ylabel(-250 "-250" -150 "-150" -50 "-50" 50 "50" 150 "150", axis(2) labsize(small) )  ///		
	legend( order( 2 "{&Euro}MTG Amortization Jan-Dec 2015" 6 "{&Delta}HH Working Hours 2015-2012" ) size(vsmall) cols(1) ring(0) position(8)) ylabel(,nogrid) addplot(pci -3000 8 3000 8, lcolor(red) || pci 0 0 0 18, lcolor(gs3) lwidth(thin) )	///
	text(-3600 -0.75 "{bf:Cohort}" , size(small)) ///
	text(-3800 -0.25 "(home purchase date)", size(vsmall))	

*********************************************
*
* Figure 6. Hours Worked: Diff-in-Diff Estimates
*
* 

use "H:\InkomenBestedingen\Data\AB\sample_event_study.dta", clear
	
areg work_hrs treated_did_hrs_2010 treated_did_hrs_2011 o.treated_did_hrs_2012 treated_did_hrs_2013 treated_did_hrs_2014 treated_did_hrs_2015 treated_did_hrs_2016 treated_did_hrs if sample_did_hrs, absorb(year) cluster(household_id)
	estimates store work_hrs				

* Note: transform(*=min(max(@,-25),75)) and transform(*=min(max(@,-250),150)) designed to prevent irrelevant high parts of CIs from shrinking observable portion
* of coefficients (which are unaffected by this as can be seen in the figure).
coefplot work_hrs, transform(*=min(max(@,-25),75)) ///
	ysc(r(-25 75) ) ///
	ylabel(-25 "-25" 0 "0" 25 "25" 50 "50" 75 "75",  labsize(small) )  ///
   xline(3, lcolor(blue) lpattern(dash)) /// 
	nooffsets vertical keep(treated_did_hrs_*) recast(connected) xlabel(,labsize(small)) xtitle("", size(small)) ytitle("# of Hours Worked") /// 
	title("") graphregion(color(white)) msize(tiny) omitted	


*********************************************

